<script setup>
import { ref, onMounted } from 'vue';
import { useRoute } from 'vue-router'

const route = useRoute();
const userId = route.query.id; // User?id=1
console.log('User Id：', userId)

let student = ref({});

onMounted(() => {
    // 模拟获取数据
    const data = [{ id: 1, name: '小张', age: 22 }, { id: 2, name: '小李', age: 33 }, { id: 3, name: '小王', age: 44 }];
    student.value = data.find(item => item.id == userId);
})
</script>

<template>
    <div>
        <h2>User Id:{{ $route.query.id }}</h2>
        {{ student.id }}.{{ student.name }}-{{ student.age }}
    </div>
</template>